/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AltaUsuario.java
 *
 * Created on 16-jul-2011, 18:32:14
 */
package ventanas;

import conexiones.AdministradorDeConexiones;
import dao.PerfilesDao;
import dao.UsuariosDao;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import modelo.Perfil;
import modelo.Usuario;

/**
 *
 * @author Matias Garcia
 */
public class ModificarUsuario extends javax.swing.JDialog {
    private static Connection conn = null;
    private static DefaultComboBoxModel modeloUsuarios;
    private static Usuario usuarioModificado;
    /** Creates new form AltaUsuario */
    public ModificarUsuario(Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        modeloUsuarios =(DefaultComboBoxModel) cBoxPerfiles.getModel();
    }

    public ModificarUsuario(Dialog parent, boolean modal) {
        super(parent, modal);
        initComponents();
        modeloUsuarios =(DefaultComboBoxModel) cBoxPerfiles.getModel();
    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        panelDatosPersona = new javax.swing.JPanel();
        lblNombre = new javax.swing.JLabel();
        lblApellido = new javax.swing.JLabel();
        lblDireccion = new javax.swing.JLabel();
        lblTelefono = new javax.swing.JLabel();
        lblCelular = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        txtApellido = new javax.swing.JTextField();
        txtDireccion = new javax.swing.JTextField();
        txtTelefono = new javax.swing.JTextField();
        txtCelular = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        lblAsteriscoNombre = new javax.swing.JLabel();
        lblAsteriscoApellido = new javax.swing.JLabel();
        lblMensaje = new javax.swing.JLabel();
        panelDatosUsuario = new javax.swing.JPanel();
        lblNombreUsuario = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        lblPerfil = new javax.swing.JLabel();
        cBoxPerfiles = new javax.swing.JComboBox();
        lblAsteriscoApellido2 = new javax.swing.JLabel();
        lblAsteriscoApellido3 = new javax.swing.JLabel();
        panelBotones = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Modificar Datos de Usuario");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        panelDatosPersona.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        lblNombre.setText("Nombre:");

        lblApellido.setText("Apellido:");

        lblDireccion.setText("Dirección:");

        lblTelefono.setText("Teléfono:");

        lblCelular.setText("Celular:");

        lblEmail.setText("E-mail:");

        lblAsteriscoNombre.setForeground(new java.awt.Color(255, 51, 0));
        lblAsteriscoNombre.setText("*");

        lblAsteriscoApellido.setForeground(new java.awt.Color(255, 51, 0));
        lblAsteriscoApellido.setText("*");

        lblMensaje.setForeground(new java.awt.Color(255, 0, 0));
        lblMensaje.setText("(*) Campos obligatorios");

        javax.swing.GroupLayout panelDatosPersonaLayout = new javax.swing.GroupLayout(panelDatosPersona);
        panelDatosPersona.setLayout(panelDatosPersonaLayout);
        panelDatosPersonaLayout.setHorizontalGroup(
            panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosPersonaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblTelefono)
                    .addComponent(lblCelular)
                    .addComponent(lblEmail)
                    .addComponent(lblDireccion)
                    .addComponent(lblApellido)
                    .addComponent(lblNombre))
                .addGap(10, 10, 10)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtNombre)
                    .addComponent(txtApellido)
                    .addComponent(txtDireccion)
                    .addComponent(txtTelefono)
                    .addComponent(txtCelular)
                    .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblAsteriscoNombre)
                    .addComponent(lblAsteriscoApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(panelDatosPersonaLayout.createSequentialGroup()
                .addGap(106, 106, 106)
                .addComponent(lblMensaje)
                .addContainerGap(104, Short.MAX_VALUE))
        );
        panelDatosPersonaLayout.setVerticalGroup(
            panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosPersonaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombre)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoNombre))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblApellido)
                    .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoApellido))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDireccion)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTelefono)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCelular)
                    .addComponent(txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosPersonaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEmail)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblMensaje)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        panelDatosUsuario.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        panelDatosUsuario.setName("panelPerfil"); // NOI18N
        panelDatosUsuario.setPreferredSize(new java.awt.Dimension(464, 75));

        lblNombreUsuario.setText("Nombre Usuario:");

        lblPerfil.setText("Perfil:");

        lblAsteriscoApellido2.setForeground(new java.awt.Color(255, 51, 0));
        lblAsteriscoApellido2.setText("*");

        lblAsteriscoApellido3.setForeground(new java.awt.Color(255, 51, 0));
        lblAsteriscoApellido3.setText("*");

        javax.swing.GroupLayout panelDatosUsuarioLayout = new javax.swing.GroupLayout(panelDatosUsuario);
        panelDatosUsuario.setLayout(panelDatosUsuarioLayout);
        panelDatosUsuarioLayout.setHorizontalGroup(
            panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelDatosUsuarioLayout.createSequentialGroup()
                .addContainerGap(22, Short.MAX_VALUE)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblPerfil)
                    .addComponent(lblNombreUsuario))
                .addGap(18, 18, 18)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cBoxPerfiles, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblAsteriscoApellido2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoApellido3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        panelDatosUsuarioLayout.setVerticalGroup(
            panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelDatosUsuarioLayout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoApellido2)
                    .addComponent(lblNombreUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelDatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPerfil)
                    .addComponent(cBoxPerfiles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAsteriscoApellido3))
                .addContainerGap())
        );

        panelBotones.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        panelBotones.setPreferredSize(new java.awt.Dimension(464, 49));

        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotonesLayout = new javax.swing.GroupLayout(panelBotones);
        panelBotones.setLayout(panelBotonesLayout);
        panelBotonesLayout.setHorizontalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotonesLayout.createSequentialGroup()
                .addGap(67, 67, 67)
                .addComponent(btnGuardar)
                .addGap(54, 54, 54)
                .addComponent(jButton1)
                .addContainerGap(56, Short.MAX_VALUE))
        );
        panelBotonesLayout.setVerticalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGuardar)
                    .addComponent(jButton1))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelDatosPersona, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelDatosUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
            .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(panelDatosPersona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelDatosUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-343)/2, (screenSize.height-418)/2, 343, 418);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // Cuando presiona la tecla SI el valor de confirmacionDeCierre() = 0 y se cierra la ventana
            if(confirmacionDeCierre() == 0 ){
                this.dispose();
            }
    }//GEN-LAST:event_jButton1ActionPerformed
    
     
    
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here: 
        if(!camposObligatorios()){
            try {
                if(txtUsuario.getText().equals(usuarioModificado.getNombreUsuario())) {
                    actualizarUsuario();
                }
                else{
                    conn = AdministradorDeConexiones.obtenerConexion();            
                    if(UsuariosDao.getInstance().verificarDisponibilidad(conn,txtUsuario.getText())){
                        actualizarUsuario();
                    }
                    else{
                        JOptionPane.showMessageDialog(this, "El nombre de usuario no esta disponible", "Error", JOptionPane.WARNING_MESSAGE);
                        txtUsuario.setText("");
                        txtUsuario.requestFocus();
                    }
                } 
            }
            catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "El usuario no fue modificado", "Error", JOptionPane.WARNING_MESSAGE);
            } 
        }
        else{
            JOptionPane.showMessageDialog(this, "Faltan cargar datos obligatorios", "Error", JOptionPane.WARNING_MESSAGE);}
           
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here: 
            if(confirmacionDeCierre() == 0 ){
                this.dispose();
            }
    }//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGuardar;
    private javax.swing.JComboBox cBoxPerfiles;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel lblApellido;
    private javax.swing.JLabel lblAsteriscoApellido;
    private javax.swing.JLabel lblAsteriscoApellido2;
    private javax.swing.JLabel lblAsteriscoApellido3;
    private javax.swing.JLabel lblAsteriscoNombre;
    private javax.swing.JLabel lblCelular;
    private javax.swing.JLabel lblDireccion;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblMensaje;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblNombreUsuario;
    private javax.swing.JLabel lblPerfil;
    private javax.swing.JLabel lblTelefono;
    private javax.swing.JPanel panelBotones;
    private javax.swing.JPanel panelDatosPersona;
    private javax.swing.JPanel panelDatosUsuario;
    private javax.swing.JTextField txtApellido;
    private javax.swing.JTextField txtCelular;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables

    public boolean camposObligatorios(){
        //Retorna true si alguno de los campos esta en blanco   
        return((txtNombre.getText().equals("")) | (txtApellido.getText().equals("")) | (txtUsuario.getText().equals("")) | (cBoxPerfiles.getSelectedIndex() == -1));
     }
   
    public int confirmacionDeCierre(){
        return(JOptionPane.showConfirmDialog(this, "Los datos no guardados se perderan ¿Desea salir?", "Advertencia", JOptionPane.YES_NO_OPTION));
    }

    private void listarPerfiles(Perfil perfil) {
        ArrayList listaPerfiles = new ArrayList();
        try {
            conn = AdministradorDeConexiones.obtenerConexion();
            listaPerfiles = PerfilesDao.getInstance().getTodos(conn);
            if(!listaPerfiles.isEmpty()){
                for (int i=0; i < listaPerfiles.size(); i++) {
                    Perfil unPerfil = (Perfil) listaPerfiles.get(i);
                    modeloUsuarios.insertElementAt(unPerfil, i);
                    if(perfil.getCod() == unPerfil.getCod()){
                        cBoxPerfiles.setSelectedIndex(i);
                    }
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(ModificarUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    void mostrarUsuario(Usuario usuario, Perfil perfil) {
        usuarioModificado = usuario;
        txtNombre.setText(usuario.getNombre());
        txtApellido.setText(usuario.getApellido());
        txtDireccion.setText(usuario.getDireccion());
        txtTelefono.setText(usuario.getTelefono());
        txtCelular.setText(usuario.getCelular());
        txtEmail.setText(usuario.getEmail());
        txtUsuario.setText(usuario.getNombreUsuario()); 
        listarPerfiles(perfil);
    }

    private void actualizarUsuario() throws Exception{
        Usuario usuario;
        int resultado;
        resultado = JOptionPane.showConfirmDialog(this, "Los datos del usuario serán modificados ¿Desea continuar?", "Advertencia", JOptionPane.YES_NO_OPTION);
        if(resultado == 0 ){
        Perfil perfil = (Perfil) modeloUsuarios.getSelectedItem();
        usuario = new Usuario(txtNombre.getText(),txtApellido.getText(),txtDireccion.getText(),txtTelefono.getText(),txtCelular.getText(),txtEmail.getText(),txtUsuario.getText(),"",perfil.getCod());
        conn = AdministradorDeConexiones.obtenerConexion(); 
        UsuariosDao.getInstance().actualizarUsuario(conn,usuarioModificado.getIdUsuario(),usuario);
        this.dispose();
        }
    }

    void mostrarDatosUsuario(Usuario usuario) {
        usuarioModificado = usuario;
        txtNombre.setText(usuario.getNombre());
        txtApellido.setText(usuario.getApellido());
        txtDireccion.setText(usuario.getDireccion());
        txtTelefono.setText(usuario.getTelefono());
        txtCelular.setText(usuario.getCelular());
        txtEmail.setText(usuario.getEmail());
        txtUsuario.setText(usuario.getNombreUsuario());
        panelDatosUsuario.setVisible(false);
        this.pack();
    }


}
